﻿Imports System.Configuration

Public Class ConfigurationHelper
    Public Shared ReadOnly Property DistripostInfoFicheLocation() As String
        Get
            Return getKeyvalue("distripostinfofichelocation")
        End Get
    End Property
    Public Shared ReadOnly Property Email1() As String
        Get
            Return getKeyvalue("email1")
        End Get
    End Property
    Public Shared ReadOnly Property Email2() As String
        Get
            Return getKeyvalue("email2")
        End Get
    End Property
    Public Shared ReadOnly Property Email3() As String
        Get
            Return getKeyvalue("email3")
        End Get
    End Property

    Public Shared ReadOnly Property ReactionsTodayEntryID() As String
        Get
            Return getKeyvalue("ReactionsTodayEntryID")
        End Get
    End Property
    Public Shared ReadOnly Property ReactionsThisWeekEntryID() As String
        Get
            Return getKeyvalue("ReactionsThisWeekEntryID")
        End Get
    End Property
    Public Shared ReadOnly Property ReactionsNextWeekEntryID() As String
        Get
            Return getKeyvalue("ReactionsNextWeekEntryID")
        End Get
    End Property

    Private Shared Function getKeyvalue(ByVal key As String) As String
        Return ConfigurationManager.AppSettings(key)
    End Function
      

    Public Shared Sub SetKeyvalue(ByVal key As String, ByVal value As String)
        Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
        Dim settings As KeyValueConfigurationCollection = config.AppSettings.Settings

        If settings(key) Is Nothing Then 'if not exist -> create
            settings.Add(key, value)
        Else 'change
            settings(key).Value = value
        End If

        config.Save(ConfigurationSaveMode.Modified)
        ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name)
    End Sub
End Class
